On Programming

Simon Mika, Cogneco AB

Simon Mika

Productivity
vs
Efficiency

The Semantic Gap

The difference between what humans understand and computers.

The Semantic Gap

The Blub Paradox

Beating the Averages by Paul Graham

"Programming Languages Vary in Power"

Abstractness Continuum

Superstitious Programmers


function isFive(value: number) {
	return value === 5
}
							

public class Car {
	bool safe;
	public bool IsSafe() {
		if (this.safe == true)
			return true;
		else
			return false;
	}
	public bool IsUnsafe() {
		return this.safe != true;
	}
}
						

public class Car {
	private string m_szBrand
	private int m_nSeats;
	public Car(string brand, int seats) {
		this.m_szBrand = brand;
		this.m_nSeats = seats;
	}
}
							

Encapsulating & Abstracting


#include <stdio.h>
#define SPEEDLIMIT 55
#define RATE 15
#define FIRST_TICKET 85
int main()
{
		int total,fine,speeding;
		speeding = FIRST_TICKET - SPEEDLIMIT;
		fine = speeding * RATE;
		total = total + fine;
		printf("For going %d in a %d zone: $%dn",
			FIRST_TICKET,SPEEDLIMIT,fine);
		printf("nTotal in fines: $%dn",total);
		return(0);
}
						

Lowest Common Denominator


								let a = b || (a && c)
							

									let a = (b - (a * c))
								

								function maximum(a, b) {
									if (a < b) 
										return a;
									else
										return b;
								}
							

								function maximum(a, b) {
									return a < b ? a : b;
								}
							

Design Patterns

instead of a better language


public class Car: IEquatable<Car> {
	public string Brand { get; }
	public int Seats { get; }
	public Car(string brand, int seats) {
		this.Brand = brand;
		this.Seats = seats;
	}
}
						

public class Car: IEquatable<Car> {
	public string Brand { get; }
	public int Seats { get; }
	public Car(string brand, int seats) {
		this.Brand = brand;
		this.Seats = seats;
	}
	public override int GetHash() {
		return (this.Brand?.GetHash() ?? 0) * 31 + 
			this.Seats.GetHash())
	}
	public override bool Equals(object other) {
		return this.Equals(other as Car)
	}
	public bool Equals(Car other) {
		return object.ReferenceEquals(other, null) && 
			this.Brand == other.Brand && 
			this.Seats == other.Seats;
	}
	public static operator bool ==(Car left, Car right) {
		return object.ReferenceEquals(left, right) || 
			!object.ReferenceEquals(left, null) && 
			left.Equals(right);
	}
	public static operator bool !=(Car left, Car right) {
		return !(left == right);
	}
}
						

public class Singleton
{
		private static Singleton instance;

		private Singleton() {}

		public static Singleton Instance
		{
			get 
			{
					if (instance == null)
					{
						instance = new Singleton();
					}
					return instance;
			}
		}
}
						

	using System;
	
	public class Singleton
	{
			Singleton() {}
			public static Singleton Instance { get; } = new Singleton();
	}
							

Simon Mika, Cogneco AB